﻿// JScript File - layoutLibrary class
//
// Convenient browser calculation functions hang off of this class.
// 
function layoutLibrary() {
    this.getOffsetLeft = getOffsetLeft;
    this.getOffsetTop = getOffsetTop;
    this.getWindowHeight = getWindowHeight;
    this.getWindowWidth = getWindowWidth;

    function getOffsetLeft(el) {
        var offset = 0;
        while (el) {
            offset += parseInt(el.offsetLeft);
            el = el.offsetParent;
        }
        if (!offset) return 0;
        return offset;
    }

    function getOffsetTop(el) {
        var offset = 0;
        while (el) {
            offset += parseInt(el.offsetTop);
            el = el.offsetParent;
        }
        if (!offset) return 0;
        return offset;
    }

    function getWindowHeight() {
        if(window.innerHeight) return window.innerHeight;
        if(document.documentElement && document.documentElement.clientHeight)return document.documentElement.clientHeight;
        if(document.body && document.body.clientHeight)return document.body.clientHeight;
        return 0;
    }
    
    function getWindowWidth() {
        if(window.innerWidth) return window.innerWidth;
        if(document.documentElement && document.documentElement.clientWidth)return document.documentElement.clientWidth;
        if(document.body && document.body.clientWidth)return document.body.clientWidth;
        return 0;
    }
}
